<?php

declare(strict_types=1);

namespace app\api\controller;

use app\common\model\Product;
use app\common\model\ProductCate;
use app\common\model\Carousel;
use app\common\tool\Result;
use app\common\controller\Config;
use think\Response;

class Index extends Base
{
    /**
     * 首页数据
     * @return Response
     */
    public function getList(): Response
    {
        $data = [
            'carousel' => Carousel::getList([],true,'sort',[],'id,images'),
            'product'     => Product::where(['status' => 1, 'pick' => 1,'cate_1'=>1])->field('id,title,icon,price,vip_price')->select(),
            'news'     => \app\common\model\News::getList([],true,'sort',[],'id,title'),
            'cate'=>ProductCate::where('status',1)->field('id,title,icon')->select(),
            'adv' => [
                ['icon'=>Config::lists()['adv']]
            ],
        ];

        return Result::success('获取成功！', $data);
    }
    /**
     * 获取协议
     * @return Response
     */
    public function communal(): Response
    {
        $type = $this->request->param('type');
        $title = ['privacy_msg' => '注册协议','web_site_title'=>'网站标题'];
        $data = [
            'title'   => $title[$type],
            'content' => handleRichText(Config::lists()[$type])
        ];
        return Result::success('获取成功！', $data);
    }
    /**
     * 获取分类
     */
    public function getCateList(): Response
    {
        $list = ProductCate::where('status',1)->field('id,title,icon')->select();
        return Result::success('获取成功！', $list);
    }
}
